<!DOCTYPE html>
<html>
<head>
    <title>新增分类</title>
    {% include 'system/common/header.html' %}
</head>
<body>
    <form class="layui-form" action="" lay-filter="category-form" style="margin: 20px;">
        <div class="mainBox">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">分类名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="required" placeholder="请输入分类名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <input type="number" name="sort" value="0" lay-verify="required|number" placeholder="请输入排序号" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit lay-filter="category-submit">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>

    {% include 'system/common/footer.html' %}
    <script>
        layui.use(['form', 'jquery'], function() {
            let form = layui.form;
            let $ = layui.jquery;

            let MODULE_PATH = "/iptvadmin/";

            // 监听提交
            form.on('submit(category-submit)', function(data) {
                let loading = layer.load();
                $.ajax({
                    url: MODULE_PATH + 'category/save',
                    data: JSON.stringify(data.field),
                    contentType: 'application/json',
                    type: 'post',
                    success: function(result) {
                        layer.close(loading);
                        if (result.success) {
                            layer.msg(result.msg, {
                                icon: 1,
                                time: 1000
                            }, function() {
                                parent.layer.close(parent.layer.getFrameIndex(window.name));
                                parent.layui.table.reload('category-table');
                            });
                        } else {
                            layer.msg(result.msg, {
                                icon: 2,
                                time: 1000
                            });
                        }
                    }
                });
                return false;
            });
        });
    </script>
</body>
</html>